import request, { download } from '@/utils/request'

/**
 * 用户信息表 Api
 *
 * @author EasyAdmin ( 1073602@qq.com )
 * @date 2025-08-26
 */
export default {

  /**
   * 分页查询
   * @param query 查询参数
   */
  page: (query: any) => {
    return request.get('/admin/system/user/page', { params: query })
  },

  /**
   * 查询列表
   * @param query 查询参数
   */
  list: (query: any) => {
    return request.get('/admin/system/user/list', { params: query })
  },

  /**
   * 查询详细
   * @param query 查询参数
   */
  getById: (id: string) => {
    return request.get(`/admin/system/user/${id}`)
  },

  /**
   * 新增
   * @param data 新增数据
   */
  add: (data: any) => {
    return request.post('/admin/system/user', data)
  },

  /**
   * 修改
   * @param data 修改数据
   */
  update: (data: any) => {
    return request.put('/admin/system/user', data)
  },

  /**
   * 删除
   * @param ids 删除Ids
   */
  delete: (ids: any) => {
    return request.delete(`/admin/system/user/${ids}`)
  },

  /**
   * 导出Excel
   * @param filename Excel文件名称
   * @param query 查询参数
   */
  download: (query: any, filename: string) => {
    download('/admin/system/user/export', { ...query }, `${filename}.xlsx`, {})
  },

  /**
   * 导出Excel
   * @param filename Excel文件名称
   * @param query 查询参数
   */
  downloadImportTemplate: (query: any, filename: string) => {
    download('/admin/system/user/importTemplate', { ...query }, `${filename}.xlsx`, {})
  },

  /**
   * 查询用户角色
   * @param userId
   * @returns
   */
  getUserRoleList: (userId: string) => {
    return request.get('/admin/system/user/role/list', { params: { userId } })
  },

  /**
   * 用户密码重置
   * @param data
   * @returns
   */
  resetUserPwd: (data: any) => {
    return request.put('/admin/system/user/resetPwd', data)
  },

  /**
   * 用户状态修改
   * @param userId
   * @param status
   * @returns
   */
  changeUserStatus: (userId: string, status: any) => {
    const data = {
      id: userId,
      status,
    }
    return request.put('/admin/system/user/changeStatus', data)
  },

  /**
   * 查询个人信息
   * @returns
   */
  getUserProfile: () => {
    return request.get('/admin/system/user/profile')
  },

  /**
   * 修改个人信息
   * @param data
   * @returns
   */
  updateUserProfile: (data: any) => {
    return request.put('/admin/system/user/profile', data)
  },

  /**
   * 修改个人头像
   * @param data
   * @returns
   */
  uploadAvatar: (data: any) => {
    return request.post('/admin/system/user/avatar', data)
  },

  /**
   * 用户密码重置
   * @param data
   * @returns
   */
  updateUserPwd: (data: any) => request({
    url: '/admin/system/user/updatePwd',
    method: 'put',
    params: data,
  }),

  /**
   * 查询部门下拉树结构
   * @returns
   */
  deptTreeSelect: () => {
    return request.get('/admin/system/dept/tree')
  },

}